#include<stdio.h>
#include<iostream>
using namespace std;

int Search(int s1[], int s2[], int L) {
	int l1 = 0, r1 = L - 1, l2 = 0, r2 = L - 1;
	if (s1[r1] <= s2[l2])
		return s1[r1];
	if (s2[r2] <= s1[l1])
		return s2[r2];

	while (l1 < r1 && l2 < r2) {
		int m1 = (l1 + r1) / 2, m2 = (l2 + r2) / 2;
		//cout << l1 << " " << r1 << " " << m1 << ";" << l2 << " " << r2 << " " << m2 << endl;
		if (s1[m1] == s2[m2])
			return s1[m1];
		else {
			if (s1[m1] < s2[m2]) {
				if ((r1 - l1 + 1) % 2 == 0)
					l1 = m1 + 1;
				else
					l1 = m1;
				r2 = m2;
			}
			else {
				if ((r1 - l1 + 1) % 2 == 0)
					l2 = m2 + 1;
				else 
					l2 = m2;
				r1 = m1;
			}
		}
		/*if (l1 == r1) {
			return s1[l1] < s2[l2] ? s1[l1] : s2[l2];
		}*/
	}
	return s1[l1] < s2[l2] ? s1[l1] : s2[l2];
}

int main() {
	int L = 5;
	int s1[5] = { 11 ,13 ,15, 17, 19 };
	int s2[5] = { 2, 4, 6, 8, 20 };
	int res = Search(s1, s2, L);
	cout << res << endl;
	return 0;
}